#include <stdio.h>
#include <string.h>
#include <limits.h>
#include "user_config.h"
#include "framework.h"
#include "service.h"







void on_detect_voltage()
{

	unsigned int ad = AD_Convert(AD_CHANNEL_INTERNAL_BOND_GAP);

	
	printf("gap:%.3fV\r\n", AD_TO_VOLT3P3(ad));
	
	
	soft_timer_start(SOFT_TIMER_DETECT_VOLTAGE, DETECT_VOLTAGE_INTERVAL);	
}



void on_key_test_short_press()
{
	printf("on key test short press\r\n");
	LED_TEST_TOGGLE();
}


void on_key_test_long_press()
{
	static unsigned char state = 0;
	
	printf("on key test long press\r\n");
	state = !state;
	if(state)
	{
		service_start();
	}
	else
	{
		service_stop();
	}
}



void service_init()
{
	event_register(EVENT_KEY_TEST_SHORT_PRESS, on_key_test_short_press);
	event_register(EVENT_KEY_TEST_LONG_PRESS, on_key_test_long_press);
	event_register(EVENT_DETECT_VOLTAGE, on_detect_voltage);

	
	soft_timer_manual_register(SOFT_TIMER_DETECT_VOLTAGE, EVENT_DETECT_VOLTAGE);
	soft_timer_start(SOFT_TIMER_DETECT_VOLTAGE, DETECT_VOLTAGE_INTERVAL);
}


void service_start()
{
	printf("service_start called\r\n");
}


void service_stop()
{
	printf("service_stop called\r\n");
}
